home *** CD-ROM | disk | FTP | other *** search
- /*----------------------------------------------------------------------------
-
- ic.c
-
- This module encapsulates the interface to the Internet Config system.
-
- Copyright © 1994-1995, Northwestern University.
-
- ----------------------------------------------------------------------------*/
-
- #include <stdio.h>
- #include <string.h>
-
- #include "glob.h"
- #include "ic.h"
- #include "ICTypes.h"
- #include "ICAPI.h"
- #include "strutil.h"
- #include "fileutil.h"
- #include "memutil.h"
- #include "apputil.h"
- #include "prefs.h"
-
-
-
- static ICInstance gInst;
- static Boolean gICStartOK = false;
-
-
-
- /*----------------------------------------------------------------------------
- MyICGetPref
-
- Get a preference from IC. Same parameters as ICGetPref.
- ----------------------------------------------------------------------------*/
-
- static pascal ICError MyICGetPref (ICInstance inst, ConstStr255Param key,
- ICAttr *attr, Ptr buf, long *size)
- {
- Str255 keyCopy; /* word-aligned to avoid crashes on 68000 Macs */
-
- CopyPascalString(keyCopy, (StringPtr)key);
- return ICGetPref(inst, keyCopy, attr, buf, size);
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyICSetPref
-
- Set a preference to IC. Same parameters as ICSetPref.
- ----------------------------------------------------------------------------*/
-
- static pascal ICError MyICSetPref (ICInstance inst, ConstStr255Param key,
- ICAttr attr, Ptr buf, long size)
- {
- Str255 keyCopy; /* word-aligned to avoid crashes on 68000 Macs */
-
- CopyPascalString(keyCopy, (StringPtr)key);
- return ICSetPref(inst, keyCopy, attr, buf, size);
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyICStart
-
- Start Internet Config.
-
- Entry: prefsFileLocated = true if we have found a NewsWatcher Prefs file,
- in which case the vRefNum and dirID params are valid,
- and we tell Internet Config to search the same folder.
- vRefNum = vol ref num of NewsWatcher Prefs file.
- dirID = dir id of NewsWatcher Prefs file.
-
- This function must be called after locating and reading NewsWatcher's
- prefs file.
- ----------------------------------------------------------------------------*/
-
- void MyICStart (Boolean prefsFileLocated, short vRefNum, long dirID)
- {
- ICError icErr, icErrCountPref;
- ICDirSpecArray dirSpecArray;
- long count;
-
- if (gICStartOK) return;
- icErr = ICStart(&gInst, kNewsWatcherSignature);
- if (icErr != noErr) return;
- if (prefsFileLocated) {
- dirSpecArray[0].vRefNum = vRefNum;
- dirSpecArray[0].dirID = dirID;
- icErr = ICFindConfigFile(gInst, 1, &dirSpecArray);
- } else {
- icErr = ICFindConfigFile(gInst, 0, nil);
- }
- if (icErr != noErr) return;
- icErr = ICBegin(gInst, icReadOnlyPerm);
- if (icErr != noErr) return;
- icErrCountPref = ICCountPref(gInst, &count);
- icErr = ICEnd(gInst);
- if (icErr != noErr) return;
- gICStartOK = icErrCountPref == noErr && count > 0;
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyICStop
-
- Stop Internet Config.
- ----------------------------------------------------------------------------*/
-
- void MyICStop (void)
- {
- if (gICStartOK) ICStop(gInst);
- gInst = nil;
- gICStartOK = false;
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReadCStringFromPString
-
- Read a C string shared pref from a P string IC pref.
-
- Entry: maxSize = max size of theString.
- key = IC keyword.
-
- Exit: theString = pref string as read from IC.
- ----------------------------------------------------------------------------*/
-
- static void ReadCStringFromPString (char *theString, long maxSize,
- ConstStr255Param key)
- {
- CStr255 str;
- ICError icErr;
- ICAttr attr;
-
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)str, &maxSize);
- if (icErr != noErr) return;
- p2cstr((StringPtr)str);
- if (EqualString(key, kICRealName, true, true)) {
- if (!ValidCString(str, sizeof(gPrefs.fullName), false)) return;
- } else if (EqualString(key, kICOrganization, true, true)) {
- if (!ValidCString(str, sizeof(gPrefs.organization), false)) return;
- } else if (EqualString(key, kICEmail, true, true)) {
- if (!ValidCString(str, sizeof(gPrefs.emailAddress), false)) return;
- }
- strcpy(theString, str);
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReadPStringFromPString
-
- Read a P string shared pref from a P string IC pref.
-
- Entry: maxSize = max size of theString.
- key = IC keyword.
-
- Exit: theString = pref string as read from IC.
- ----------------------------------------------------------------------------*/
-
- static void ReadPStringFromPString (StringPtr theString, long maxSize,
- ConstStr255Param key)
- {
- Str255 str;
- ICError icErr;
- ICAttr attr;
-
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)str, &maxSize);
- if (icErr != noErr) return;
- if (EqualString(key, kICNNTPHost, true, true)) {
- if (!ValidPString(str, sizeof(gPrefs.newsServerName), false)) return;
- } else if (EqualString(key, kICSMTPHost, true, true)) {
- if (!ValidPString(str, sizeof(gPrefs.mailServerName), false)) return;
- }
- CopyPascalString(theString, str);
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReadCStringFromText
-
- Read a C string shared pref from a text IC pref.
-
- Entry: maxSize = max size of theString.
- key = IC keyword.
-
- Exit: theString = pref string as read from IC.
- ----------------------------------------------------------------------------*/
-
- static void ReadCStringFromText (char *theString, long maxSize,
- ConstStr255Param key)
- {
- char buf[4096];
- ICError icErr;
- ICAttr attr;
- long size;
-
- size = maxSize - 1;
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)buf, &size);
- if (icErr != noErr) return;
- buf[size] = 0;
- if (EqualString(key, kICSignature, true, true)) {
- if (!ValidCString(buf, sizeof(gPrefs.signature), true)) return;
- }
- BlockMoveData(buf, theString, size+1);
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReadFolderFromFileSpec
-
- Read a default folder shared pref from an ICFileSpec IC pref.
-
- Entry: key = IC keyword.
-
- Exit: *defaultFolderAlias = handle to default folder alias.
- ----------------------------------------------------------------------------*/
-
- static void ReadFolderFromFileSpec (AliasHandle *defaultFolderAlias,
- ConstStr255Param key)
- {
- char buf[4096];
- ICError icErr;
- ICAttr attr;
- long size;
- ICFileSpec *p;
- AliasHandle alias;
- OSErr err = noErr;
-
- size = sizeof(buf);
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)buf, &size);
- if (icErr == noErr) {
- p = (ICFileSpec*)buf;
- if (p->alias.aliasSize == 0) {
- err = VolNameAndCreationDateToVRefNum(p->vol_name, p->vol_creation_date,
- &p->fss.vRefNum);
- if (err != noErr) return;
- err = NewAlias(nil, &p->fss, &alias);
- if (err != noErr) return;
- } else {
- err = MyNewHandle(p->alias.aliasSize, &alias);
- if (err != noErr) return;
- BlockMoveData(&p->alias, *alias, p->alias.aliasSize);
- }
- MyDisposeHandle(*defaultFolderAlias);
- *defaultFolderAlias = alias;
- }
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReadFontInfo
-
- Read font info from an ICFontRecord IC pref.
-
- Entry: key = IC keyword.
-
- Exit: fontName = font name as read from IC.
- *fontSize = font size as read from IC.
- ----------------------------------------------------------------------------*/
-
- static void ReadFontInfo (Str255 fontName, short *fontSize,
- ConstStr255Param key)
- {
- ICError icErr;
- ICFontRecord icFontRecord;
- ICAttr attr;
- long size;
-
- size = sizeof(icFontRecord);
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)&icFontRecord, &size);
- if (icErr != noErr) return;
- if (size <= 4 || icFontRecord.size == 0 || *icFontRecord.font == 0) return;
- if (!ValidPString(icFontRecord.font, 255, false)) return;
- CopyPascalString(fontName, icFontRecord.font);
- *fontSize = icFontRecord.size;
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReadURLHelperInfo
-
- Read URL Helper info.
- ----------------------------------------------------------------------------*/
-
- static void ReadURLHelperInfo (void)
- {
- ICError icErr;
- Str255 key;
- long i, count;
- short prefixLen, schemeNameLen;
- TURLSchemeName schemeName;
- TURLHelperInfo **h = nil;
- OSErr err = noErr;
- TURLHelperInfo helperInfo;
- TURLHelperInfo *p;
- ICAppSpec icAppSpec;
- ICAttr attr;
- long size, hSize = 0;
- short numHelpers = 0;
-
- err = MyNewHandle(0, &h);
- if (err != noErr) goto exit;
-
- prefixLen = *kICHelper;
-
- icErr = ICCountPref(gInst, &count);
- if (icErr != noErr) goto exit;
-
- for (i = 1; i <= count; i++) {
- icErr = ICGetIndPref(gInst, i, key);
- if (icErr != noErr) goto exit;
- schemeNameLen = *key - prefixLen;
- if (schemeNameLen > 0 && schemeNameLen <= kMaxSchemeNameLen &&
- MyStrNEqual((char*)key+1, (char*)kICHelper+1, prefixLen))
- {
- BlockMoveData(key + prefixLen + 1, schemeName, schemeNameLen);
- schemeName[schemeNameLen] = 0;
- if (!MyStrEqual(schemeName, "editor") && !MyStrEqual(schemeName, "mailto") &&
- !MyStrEqual(schemeName, "nntp") && !MyStrEqual(schemeName, "news"))
- {
- size = sizeof(icAppSpec);
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)&icAppSpec, &size);
- if (icErr != noErr) goto exit;
- strcpy(helperInfo.schemeName, schemeName);
- helperInfo.sig = icAppSpec.fCreator;
- helperInfo.versionNumber = 0;
- helperInfo.lastMod = 0;
- for (p = *gPrefs.urlHelpers; *p->schemeName != 0; p++) {
- if (MyStrEqual(schemeName, p->schemeName)) {
- if (helperInfo.sig == p->sig) {
- helperInfo.versionNumber = p->versionNumber;
- helperInfo.lastMod = p->lastMod;
- }
- break;
- }
- }
- hSize += sizeof(TURLHelperInfo);
- err = MySetHandleSize(h, hSize);
- if (err != noErr) goto exit;
- (*h)[numHelpers] = helperInfo;
- numHelpers++;
- }
- }
- }
-
- hSize += sizeof(TURLHelperInfo);
- err = MySetHandleSize(h, hSize);
- memset(*h + numHelpers, 0, sizeof(TURLHelperInfo));
-
- MyDisposeHandle(gPrefs.urlHelpers);
- gPrefs.urlHelpers = h;
-
- return;
-
- exit:
-
- MyDisposeHandle(h);
- return;
- }
-
-
-
- /*----------------------------------------------------------------------------
- ReadEditorInfo
-
- Read text editor info from an ICAppSpec IC pref.
-
- Exit: *sig = signature of editor applicaton.
- ----------------------------------------------------------------------------*/
-
- static void ReadEditorInfo (OSType *sig)
- {
- ICError icErr;
- ICAppSpec icAppSpec;
- ICAttr attr;
- long size;
-
- size = sizeof(icAppSpec);
- icErr = MyICGetPref(gInst, kICeditorHelper, &attr, (Ptr)&icAppSpec, &size);
- if (icErr == noErr) *sig = icAppSpec.fCreator;
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyICReadURLHelperPref
-
- Read a URL helper program Internet Config pref.
-
- Entry: schemeName = URL scheme name.
- ----------------------------------------------------------------------------*/
-
- void MyICReadURLHelperPref (TURLSchemeName schemeName)
- {
- ICError icErr;
- Str255 key;
- short len;
- ICAppSpec icAppSpec;
- ICAttr attr;
- long size;
- short i;
- TURLHelperInfo *p;
- OSErr err = noErr;
-
- if (!gICStartOK) return;
-
- icErr = ICBegin(gInst, icReadOnlyPerm);
- if (icErr != noErr) return;
-
- CopyPascalString(key, kICHelper);
- len = strlen(schemeName);
- BlockMoveData(schemeName, key + *key + 1, len);
- *key += len;
-
- size = sizeof(icAppSpec);
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)&icAppSpec, &size);
- if (icErr != noErr && icErr != icPrefNotFoundErr) goto exit;
-
- for (i = 0, p = *gPrefs.urlHelpers; *p->schemeName != 0; i++, p++) {
- if (MyStrEqual(schemeName, p->schemeName)) break;
- }
-
- if (icErr == noErr) {
- if (*p->schemeName == 0) {
- /* IC has this scheme, but NW does not. Add the new scheme to the end of
- the gPrefs.urlHelpers array. */
- size = MyGetHandleSize(gPrefs.urlHelpers);
- err = MySetHandleSize(gPrefs.urlHelpers, size + sizeof(TURLHelperInfo));
- if (err != noErr) goto exit;
- p = &(*gPrefs.urlHelpers)[i];
- strcpy(p->schemeName, schemeName);
- p->sig = icAppSpec.fCreator;
- p->versionNumber = 0;
- p->lastMod = 0;
- memset(p+1, 0, sizeof(TURLHelperInfo));
- } else {
- /* Both IC and NW have this scheme. Update the info for this helper in
- the gPrefs.urlHelpers array. */
- if (icAppSpec.fCreator == p->sig) goto exit;
- p->sig = icAppSpec.fCreator;
- p->versionNumber = 0;
- p->lastMod = 0;
- }
- } else {
- if (*p->schemeName == 0) {
- /* IC does not have this scheme, and neither does NW. Just return. */
- goto exit;
- } else {
- /* IC does not have this scheme, but NW does. Delete it from the
- gPrefs.urlHelpers array. */
- size = MyGetHandleSize(gPrefs.urlHelpers);
- BlockMoveData(
- *gPrefs.urlHelpers + i + 1,
- *gPrefs.urlHelpers + i,
- size - (i+1) * sizeof(TURLHelperInfo));
- MySetHandleSize(gPrefs.urlHelpers, size - sizeof(TURLHelperInfo));
- }
- }
-
- exit:
-
- ICEnd(gInst);
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyICReadSharedPrefs
-
- Read shared Internet Config prefs.
-
- Entry: key = IC keyword for shared pref.
- ----------------------------------------------------------------------------*/
-
- void MyICReadSharedPrefs (ConstStr255Param key)
- {
- ICError icErr;
-
- if (!gICStartOK) return;
-
- icErr = ICBegin(gInst, icReadOnlyPerm);
- if (icErr != noErr) return;
-
- if (EqualString(key, kICAllSharedPrefs, true, true)) {
- ReadCStringFromPString(gPrefs.fullName, sizeof(gPrefs.fullName),
- kICRealName);
- ReadCStringFromPString(gPrefs.organization, sizeof(gPrefs.organization),
- kICOrganization);
- ReadCStringFromPString(gPrefs.quoteString, sizeof(gPrefs.quoteString),
- kICQuotingString);
- ReadCStringFromText(gPrefs.signature, sizeof(gPrefs.signature),
- kICSignature);
- ReadCStringFromPString(gPrefs.emailAddress, sizeof(gPrefs.emailAddress),
- kICEmail);
- ReadPStringFromPString(gPrefs.mailServerName, sizeof(gPrefs.mailServerName),
- kICSMTPHost);
- ReadCStringFromText(gPrefs.extraMailHdrLines, sizeof(gPrefs.extraMailHdrLines),
- kICMailHeaders);
- ReadCStringFromPString(gPrefs.authUsername, sizeof(gPrefs.authUsername),
- kICNewsAuthUsername);
- ReadCStringFromPString(gPrefs.authPassword, sizeof(gPrefs.authPassword),
- kICNewsAuthPassword);
- ReadPStringFromPString(gPrefs.newsServerName, sizeof(gPrefs.newsServerName),
- kICNNTPHost);
- ReadCStringFromText(gPrefs.extraNewsHdrLines, sizeof(gPrefs.extraNewsHdrLines),
- kICNewsHeaders);
- ReadFolderFromFileSpec(&gPrefs.savedBinDefaultFolderAlias, kICDownloadFolder);
- ReadFontInfo(gPrefs.textFont, &gPrefs.textSize, kICScreenFont);
- ReadFontInfo(gPrefs.listFont, &gPrefs.listSize, kICListFont);
- ReadFontInfo(gPrefs.printingFont, &gPrefs.printingSize, kICPrinterFont);
- ReadURLHelperInfo();
- ReadEditorInfo(&gPrefs.savedArtCreator);
- } else if (EqualString(key, kICRealName, true, true)) {
- ReadCStringFromPString(gPrefs.fullName, sizeof(gPrefs.fullName),
- kICRealName);
- } else if (EqualString(key, kICOrganization, true, true)) {
- ReadCStringFromPString(gPrefs.organization, sizeof(gPrefs.organization),
- kICOrganization);
- } else if (EqualString(key, kICQuotingString, true, true)) {
- ReadCStringFromPString(gPrefs.quoteString, sizeof(gPrefs.quoteString),
- kICQuotingString);
- } else if (EqualString(key, kICSignature, true, true)) {
- ReadCStringFromText(gPrefs.signature, sizeof(gPrefs.signature),
- kICSignature);
- } else if (EqualString(key, kICEmail, true, true)) {
- ReadCStringFromPString(gPrefs.emailAddress, sizeof(gPrefs.emailAddress),
- kICEmail);
- } else if (EqualString(key, kICSMTPHost, true, true)) {
- ReadPStringFromPString(gPrefs.mailServerName, sizeof(gPrefs.mailServerName),
- kICSMTPHost);
- } else if (EqualString(key, kICMailHeaders, true, true)) {
- ReadCStringFromText(gPrefs.extraMailHdrLines, sizeof(gPrefs.extraMailHdrLines),
- kICMailHeaders);
- } else if (EqualString(key, kICNewsAuthUsername, true, true)) {
- ReadCStringFromPString(gPrefs.authUsername, sizeof(gPrefs.authUsername),
- kICNewsAuthUsername);
- } else if (EqualString(key, kICNewsAuthPassword, true, true)) {
- ReadCStringFromPString(gPrefs.authPassword, sizeof(gPrefs.authPassword),
- kICNewsAuthPassword);
- } else if (EqualString(key, kICNNTPHost, true, true)) {
- ReadPStringFromPString(gPrefs.newsServerName, sizeof(gPrefs.newsServerName),
- kICNNTPHost);
- } else if (EqualString(key, kICNewsHeaders, true, true)) {
- ReadCStringFromText(gPrefs.extraNewsHdrLines, sizeof(gPrefs.extraNewsHdrLines),
- kICNewsHeaders);
- } else if (EqualString(key, kICDownloadFolder, true, true)) {
- ReadFolderFromFileSpec(&gPrefs.savedBinDefaultFolderAlias, kICDownloadFolder);
- } else if (EqualString(key, kICScreenFont, true, true)) {
- ReadFontInfo(gPrefs.textFont, &gPrefs.textSize, kICScreenFont);
- } else if (EqualString(key, kICListFont, true, true)) {
- ReadFontInfo(gPrefs.listFont, &gPrefs.listSize, kICListFont);
- } else if (EqualString(key, kICPrinterFont, true, true)) {
- ReadFontInfo(gPrefs.printingFont, &gPrefs.printingSize, kICPrinterFont);
- } else if (EqualString(key, kICeditorHelper, true, true)) {
- ReadEditorInfo(&gPrefs.savedArtCreator);
- }
-
- ICEnd(gInst);
- }
-
-
-
- /*----------------------------------------------------------------------------
- WriteCStringToPString
-
- Write a C string shared pref to a P string IC pref.
-
- Entry: theString = pointer to C string shared pref.
- key = IC keyword.
- ----------------------------------------------------------------------------*/
-
- static void WriteCStringToPString (char *theString, ConstStr255Param key)
- {
- c2pstr(theString);
- MyICSetPref(gInst, key, ICattr_no_change, (Ptr)theString, *theString+1);
- p2cstr((StringPtr)theString);
- }
-
-
-
- /*----------------------------------------------------------------------------
- WritePStringToPString
-
- Write a P string shared pref to a P string IC pref.
-
- Entry: theString = pointer to P string shared pref.
- key = IC keyword.
- ----------------------------------------------------------------------------*/
-
- static void WritePStringToPString (StringPtr theString, ConstStr255Param key)
- {
- MyICSetPref(gInst, key, ICattr_no_change, (Ptr)theString, *theString+1);
- }
-
-
-
- /*----------------------------------------------------------------------------
- WriteCStringToText
-
- Write a C string shared pref to a text IC pref.
-
- Entry: theString = pointer to C string shared pref.
- key = IC keyword.
- ----------------------------------------------------------------------------*/
-
- static void WriteCStringToText (char *theString, ConstStr255Param key)
- {
- MyICSetPref(gInst, key, ICattr_no_change, (Ptr)theString, strlen(theString));
- }
-
-
-
- /*----------------------------------------------------------------------------
- WriteFolderToFileSpec
-
- Write a default folder shared pref to an ICFileSpec IC pref.
-
- Entry: defaultFolderAlias = Handle to alias for default folder
- key = IC keyword.
- ----------------------------------------------------------------------------*/
-
- static void WriteFolderToFileSpec (AliasHandle defaultFolderAlias,
- ConstStr255Param key)
- {
- char buf[4096];
- OSErr err = noErr;
- ICFileSpec *p;
- HParamBlockRec pb;
- Str31 volName;
- long aliasSize, size;
- FSSpec fss;
- Boolean wasChanged;
-
- if (defaultFolderAlias == nil) return;
- err = ResolveAlias(nil, defaultFolderAlias, &fss, &wasChanged);
- if (err != noErr) return;
- pb.volumeParam.ioNamePtr = volName;
- pb.volumeParam.ioVolIndex = 0;
- pb.volumeParam.ioVRefNum = fss.vRefNum;
- err = PBHGetVInfoSync(&pb);
- p = (ICFileSpec*)buf;
- CopyPascalString(p->vol_name, volName);
- p->vol_creation_date = pb.volumeParam.ioVCrDate;
- p->fss = fss;
- aliasSize = (**defaultFolderAlias).aliasSize;
- size = aliasSize + sizeof(Str31) + sizeof(long) + sizeof(FSSpec);
- if (size > sizeof(buf)) return;
- BlockMoveData(*defaultFolderAlias, &p->alias, aliasSize);
- MyICSetPref(gInst, key, ICattr_no_change, (Ptr)buf, size);
- }
-
-
-
- /*----------------------------------------------------------------------------
- WriteFontInfo
-
- Read font info to an ICFontRecord IC pref.
-
- Entry: fontName = font name.
- fontSize = font size.
- key = IC keyword.
- ----------------------------------------------------------------------------*/
-
- static void WriteFontInfo (Str255 fontName, short fontSize,
- ConstStr255Param key)
- {
- ICError icErr;
- ICFontRecord icFontRecord;
- ICAttr attr;
- long size;
-
- size = sizeof(icFontRecord);
- icErr = MyICGetPref(gInst, key, &attr, (Ptr)&icFontRecord, &size);
- if (icErr == icPrefNotFoundErr) {
- icFontRecord.face = normal;
- } else if (icErr != noErr) {
- return;
- }
- CopyPascalString(icFontRecord.font, fontName);
- icFontRecord.size = fontSize;
- MyICSetPref(gInst, key, ICattr_no_change, (Ptr)&icFontRecord, sizeof(icFontRecord));
- }
-
-
-
- /*----------------------------------------------------------------------------
- WriteURLHelperInfo
-
- Write URL Helper info.
- ----------------------------------------------------------------------------*/
-
- static void WriteURLHelperInfo (void)
- {
- ICError icErr;
- Str255 key;
- long i, count;
- short prefixLen, schemeNameLen;
- TURLSchemeName schemeName;
- TURLHelperInfo *p;
- Str255 **keysToDelete = nil;
- short numKeysToDelete = 0;
- OSErr err = noErr;
- TURLHelperInfo helperInfo;
- ICAppSpec icAppSpec;
-
- err = MyNewHandle(0, &keysToDelete);
- if (err != noErr) goto exit;
-
- prefixLen = *kICHelper;
-
- icErr = ICCountPref(gInst, &count);
- if (icErr != noErr) goto exit;
-
- for (i = 1; i <= count; i++) {
- icErr = ICGetIndPref(gInst, i, key);
- if (icErr != noErr) goto exit;
- schemeNameLen = *key - prefixLen;
- if (schemeNameLen > 0 && schemeNameLen <= kMaxSchemeNameLen &&
- MyStrNEqual((char*)key+1, (char*)kICHelper+1, prefixLen))
- {
- BlockMoveData(key + prefixLen + 1, schemeName, schemeNameLen);
- schemeName[schemeNameLen] = 0;
- if (!MyStrEqual(schemeName, "editor") && !MyStrEqual(schemeName, "mailto") &&
- !MyStrEqual(schemeName, "nntp") && !MyStrEqual(schemeName, "news"))
- {
- for (p = *gPrefs.urlHelpers; *p->schemeName != 0; p++) {
- if (MyStrEqual(schemeName, p->schemeName)) break;
- }
- if (*p->schemeName == 0) {
- numKeysToDelete++;
- err = MySetHandleSize(keysToDelete, numKeysToDelete * sizeof(Str255));
- if (err != noErr) goto exit;
- BlockMoveData(key, *keysToDelete + numKeysToDelete - 1, sizeof(Str255));
- }
- }
- }
- }
-
- for (i = 0; i < numKeysToDelete; i++) {
- BlockMoveData(*keysToDelete + i, key, sizeof(Str255));
- ICDeletePref(gInst, key);
- }
-
- for (i = 0; ; i++) {
- helperInfo = (*gPrefs.urlHelpers)[i];
- if (*helperInfo.schemeName == 0) break;
- CopyPascalString(key, kICHelper);
- schemeNameLen = strlen(helperInfo.schemeName);
- BlockMoveData(helperInfo.schemeName, key + prefixLen + 1, schemeNameLen);
- *key += schemeNameLen;
- icAppSpec.fCreator = helperInfo.sig;
- *icAppSpec.name = 0;
- FindAppNameFromSig(helperInfo.sig, icAppSpec.name);
- MyICSetPref(gInst, key, ICattr_no_change, (Ptr)&icAppSpec, sizeof(icAppSpec));
- }
-
- exit:
-
- MyDisposeHandle(keysToDelete);
-
- }
-
-
-
- /*----------------------------------------------------------------------------
- WriteEditorInfo
-
- Write Editor info to the "editor" helper ICAppSpec IC pref.
-
- Entry: sig = editor helper signature.
- ----------------------------------------------------------------------------*/
-
- static void WriteEditorInfo (OSType sig)
- {
- ICAppSpec icAppSpec;
- long size;
- OSErr err = noErr;
-
- icAppSpec.fCreator = sig;
- err = FindAppNameFromSig(sig, icAppSpec.name);
- if (err != noErr) *icAppSpec.name = 0;
- size = sizeof(icAppSpec);
- MyICSetPref(gInst, kICeditorHelper, ICattr_no_change, (Ptr)&icAppSpec, size);
- }
-
-
-
- /*----------------------------------------------------------------------------
- MyICWriteSharedPrefs
-
- Write shared Internet Config prefs.
-
- Entry: key = IC keyword for shared pref.
- ----------------------------------------------------------------------------*/
-
- void MyICWriteSharedPrefs (ConstStr255Param key)
- {
- ICError icErr;
-
- if (!gICStartOK) return;
-
- icErr = ICBegin(gInst, icReadWritePerm);
- if (icErr != noErr) return;
-
- if (EqualString(key, kICAllSharedPrefs, true, true)) {
- WriteCStringToPString(gPrefs.fullName, kICRealName);
- WriteCStringToPString(gPrefs.organization, kICOrganization);
- WriteCStringToPString(gPrefs.quoteString, kICQuotingString);
- WriteCStringToText(gPrefs.signature, kICSignature);
- WriteCStringToPString(gPrefs.emailAddress, kICEmail);
- WritePStringToPString(gPrefs.mailServerName, kICSMTPHost);
- WriteCStringToText(gPrefs.extraMailHdrLines, kICMailHeaders);
- WriteCStringToPString(gPrefs.authUsername, kICNewsAuthUsername);
- WriteCStringToPString(gPrefs.authPassword, kICNewsAuthPassword);
- WritePStringToPString(gPrefs.newsServerName, kICNNTPHost);
- WriteCStringToText(gPrefs.extraNewsHdrLines, kICNewsHeaders);
- WriteFolderToFileSpec(gPrefs.savedBinDefaultFolderAlias, kICDownloadFolder);
- WriteFontInfo(gPrefs.textFont, gPrefs.textSize, kICScreenFont);
- WriteFontInfo(gPrefs.listFont, gPrefs.listSize, kICListFont);
- WriteFontInfo(gPrefs.printingFont, gPrefs.printingSize, kICPrinterFont);
- WriteURLHelperInfo();
- WriteEditorInfo(gPrefs.savedArtCreator);
- } else if (EqualString(key, kICRealName, true, true)) {
- WriteCStringToPString(gPrefs.fullName, kICRealName);
- } else if (EqualString(key, kICOrganization, true, true)) {
- WriteCStringToPString(gPrefs.organization, kICOrganization);
- } else if (EqualString(key, kICQuotingString, true, true)) {
- WriteCStringToPString(gPrefs.quoteString, kICQuotingString);
- } else if (EqualString(key, kICSignature, true, true)) {
- WriteCStringToText(gPrefs.signature, kICSignature);
- } else if (EqualString(key, kICEmail, true, true)) {
- WriteCStringToPString(gPrefs.emailAddress, kICEmail);
- } else if (EqualString(key, kICSMTPHost, true, true)) {
- WritePStringToPString(gPrefs.mailServerName, kICSMTPHost);
- } else if (EqualString(key, kICMailHeaders, true, true)) {
- WriteCStringToText(gPrefs.extraMailHdrLines, kICMailHeaders);
- } else if (EqualString(key, kICNewsAuthUsername, true, true)) {
- WriteCStringToPString(gPrefs.authUsername, kICNewsAuthUsername);
- } else if (EqualString(key, kICNewsAuthPassword, true, true)) {
- WriteCStringToPString(gPrefs.authPassword, kICNewsAuthPassword);
- } else if (EqualString(key, kICNNTPHost, true, true)) {
- WritePStringToPString(gPrefs.newsServerName, kICNNTPHost);
- } else if (EqualString(key, kICNewsHeaders, true, true)) {
- WriteCStringToText(gPrefs.extraNewsHdrLines, kICNewsHeaders);
- } else if (EqualString(key, kICDownloadFolder, true, true)) {
- WriteFolderToFileSpec(gPrefs.savedBinDefaultFolderAlias, kICDownloadFolder);
- } else if (EqualString(key, kICScreenFont, true, true)) {
- WriteFontInfo(gPrefs.textFont, gPrefs.textSize, kICScreenFont);
- } else if (EqualString(key, kICListFont, true, true)) {
- WriteFontInfo(gPrefs.listFont, gPrefs.listSize, kICListFont);
- } else if (EqualString(key, kICPrinterFont, true, true)) {
- WriteFontInfo(gPrefs.printingFont, gPrefs.printingSize, kICPrinterFont);
- } else if (EqualString(key, kICeditorHelper, true, true)) {
- WriteEditorInfo(gPrefs.savedArtCreator);
- }
-
- ICEnd(gInst);
- }
-